import { customSort } from '@/scripts/tools.js';
export default {
  methods: {
    sortData(column, tableData, params) {
      if (params) {
        column.forEach(item => {
          if (item.key === params.key) {
            item.sortBy = params.order;
          } else if (typeof item.key === 'string') {
            item.sortBy = true;
          } else {
            // sonar
          }
        });
      }
      const result = column.find(item => typeof item.sortBy === 'string');
      if (!result) {
        return;
      }
      const { key, sortBy } = result;
      const symbolTip = sortBy === 'desc' ? -1 : 1;
      this[tableData] = customSort(this[tableData], key, symbolTip);
    },
  },
};
